<?php 
/*
TAGS.INC.PHP by martin $ 2009/12/22 21:30:11
*/

$aim = isset($aim) ? $aim : '';
$tag = g_('aim') != '' ? g_('aim') : $aim;
$body = '';

include_once (OD.'tags.ini.php');

$LINES = array();

if(!empty($tag)){
 $tag = str_replace(array('&amp;'), array('&'), urldecode($tag));
 $hit = preg_grep('{'.preg_quote($tag).'\|}', $TAGS_LIST);
 $hit = array_values($hit);
 if(!empty($hit)){
  $hit = str_replace("$tag|", '', $hit[0]);
  $ids = explode(',', $hit);
  foreach ($ids as $id){
   if(!ADMIN && substr($id, 10, 1)=='d') continue;
   $log = log_($id);
   if($log==''){
    continue;
   }
   $line = preg_grep("/$id/", file($log));
   $line = array_values($line);
   if(!empty($line)) $LINES[] = $line[0];
  }
  $tag = str_replace('+', ' ', $tag);
 }
 $DIVISION['header'] .= '<h3 class="tags-nav center">[ <a href="'.(MODE_STATIC ? ROOT_PATH.'tags/' : 'index.php?mode=tags').'">Tags</a> :: '.$tag.' ]</h3>'.NL;
 $LINES = array_unique($LINES);
 if(!empty($LINES)){
  usort($LINES, 'SORT_BY_DATE');
  if($displayMode=='list'){
   show_lists($LINES);
  } else HEADLINE_MODE ? show_headline($LINES) : show_box_all($LINES);
 } else return $DIVISION['body'] .= '<p class="alert">このタグでのエントリーはないようです…</p>';
} else {
 if(!empty($_cache['tags'])){
  $body .= '<div class="tags-list">'.NL;
  $body .= '<h3>[ '.sizeof($_cache['tags']).' 個のタグエントリー ]</h3>'.NL;
  $body .= ' <ul>'.NL;
  foreach ($_cache['tags'] as $tag=>$size){
   list($nominal, $real) = explode('|', $size[0]);
   $size[0] = ADMIN ? $real : $nominal;
   $fontsize = ($fontsize = (int)(TAG_MIN_FONT_SIZE + $size[0])) > TAG_MAX_FONT_SIZE ? TAG_MAX_FONT_SIZE : $fontsize;
   $fontsize = ' style="font-size:'.$fontsize.'px"';
   $body .= '  <li><a href="'.(MODE_STATIC ? ROOT_PATH.'tags/' : 'index.php?mode=tags&amp;aim=').urlencode(urlencode($tag)).$apres.'" rel="tag"'
         .$fontsize.' title="'.$size[0].'個のエントリー">'.$tag.'</a></li>'.NL;
  }
  $body .= ' </ul>'.NL.'</div><!--#tag-list-->'.NL;
 } else {
  $body .= '<h4 class="alert">このブログでタグは使われていないようです</h4>';
 }
 return $DIVISION['body'] .= $body;
}

?>